// 从插件内导出reateRouter、createWebHashHistory
import { createRouter, createWebHashHistory } from "vue-router";


import LoginCom from "@/components/LoginCom.vue";
import HomeCom from "@/components/HomeCom.vue";
import AddPersonCom from "@/components/AddPersonCom.vue"
import ListPersonCom from "@/components/ListPersonCom.vue"
import SchoolList from "@/components/SchoolList.vue"
import RegisterCom from "@/components/RegisterCom.vue"
import EditPerson from "@/components/EditPerson.vue"
import ProductList from "@/components/ProductList.vue"
import EditProd from "@/components/EditProd.vue"
// 定义路由表
const routes=[
    // 一个地址配置：/home的路径对应的组件是IndexCom
    {
        // ：路由地址
        path:'/',
         redirect: {
            name:'LoginCom'
         },
    },
        {
            // ：路由地址
            path:'/login',
            name:'LoginCom',
            component : LoginCom,
        },
        {
                path:'/register',
                name:'RegisterCom',
                component:RegisterCom,
        },
        {
            path:'/home',
            name:'HomeCom',
            component : HomeCom,
            // children属性：设置首页的子路由
            children:[
                {
                    path:'add',
                    name:'AddPersonCom',
                    component:AddPersonCom
                },
                {
                    path:'list',
                    name:'ListPersonCom',
                    component:ListPersonCom
                },
                {
                    path:'/school',
                    name:'SchoolList',
                    component:SchoolList,
                },
                {
                    path:'editperson',
                    name:'EditPerson',
                    component:EditPerson
                },
                {
                    path:'product',
                    name:'ProductList',
                    component:ProductList
                },
                {
                    path:'editprod',
                    name:'EditProd',
                    component:EditProd
                }
            ]
        }
];

// 定义路由器、创建路由器
const router=createRouter({
    // 调用路由表，实现router-link的跳转以及router-view的渲染
    // routes:routes,
    routes,

    // 将路由历史模式设置为hash模式（哈希历史）
history:createWebHashHistory(),
});

// 导出路由器
export default router;